<template>
  <div class="preview-phone">
    <div class="phone-frame">
      <div class="phone-notch"></div>
      <div class="phone-screen">
        <div class="status-bar">
          <span class="time">9:41</span>
          <div class="indicators">
            <span class="signal">●●●</span>
            <span class="wifi">📶</span>
            <span class="battery">🔋</span>
          </div>
        </div>

        <div class="app-header">
          <div class="header-left">
            <ArrowLeftOutlined />
          </div>
          <div class="header-title">圈子</div>
          <div class="header-right">
            <MoreOutlined />
          </div>
        </div>

        <div class="post-container">
          <div class="post-header">
            <img :src="userAvatar" class="user-avatar" />
            <div class="user-info">
              <div class="username">{{ displayUsername }}</div>
              <div class="post-meta">
                <span class="school">{{ previewData.schoolName || '未选择学校' }}</span>
                <span class="separator">·</span>
                <span class="category">{{ previewData.categoryName || '未选择分类' }}</span>
                <span class="separator">·</span>
                <span class="time">刚刚</span>
              </div>
            </div>
          </div>

          <div class="post-content">
            <h3 class="post-title">{{ previewData.title || '帖子标题' }}</h3>
            <p class="post-text">{{ previewData.content || '这里是帖子内容...' }}</p>

            <!-- 话题标签 -->
            <div class="post-tags" v-if="previewData.tags && previewData.tags.length > 0">
              <span v-for="tag in previewData.tags" :key="tag" class="tag"> #{{ tag }} </span>
            </div>

            <!-- 图片展示 -->
            <div class="post-images" v-if="previewData.images && previewData.images.length > 0">
              <div v-if="previewData.images.length === 1" class="single-image">
                <img :src="previewData.images[0]" />
              </div>
              <div v-else-if="previewData.images.length <= 4" class="grid-images">
                <img
                  v-for="(image, index) in previewData.images.slice(0, 4)"
                  :key="index"
                  :src="image"
                  :class="`grid-${Math.min(previewData.images.length, 4)}`"
                />
              </div>
              <div v-else class="carousel-images">
                <div class="carousel-container">
                  <img :src="previewData.images[0]" />
                  <div class="image-count">1/{{ previewData.images.length }}</div>
                </div>
              </div>
            </div>
          </div>

          <div class="post-actions">
            <div class="action-item">
              <HeartOutlined class="action-icon" />
              <span class="action-count">{{ previewData.likeCount }}</span>
            </div>
            <div class="action-item">
              <EyeOutlined class="action-icon" />
              <span class="action-count">{{ previewData.viewCount }}</span>
            </div>
            <div class="action-item">
              <MessageOutlined class="action-icon" />
              <span class="action-count">{{ previewData.commentCount }}</span>
            </div>
            <div class="action-item">
              <ShareAltOutlined class="action-icon" />
              <span class="action-text">分享</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import {
  ArrowLeftOutlined,
  MoreOutlined,
  HeartOutlined,
  EyeOutlined,
  MessageOutlined,
  ShareAltOutlined,
} from '@ant-design/icons-vue'

interface PreviewData {
  title: string
  content: string
  images: string[]
  tags: string[]
  isAnonymous: number
  userAvatar: string
  userNickname: string
  likeCount: number
  viewCount: number
  commentCount: number
  schoolName: string
  categoryName: string
}

interface Props {
  previewData: PreviewData
}

const props = defineProps<Props>()

// 计算显示的用户名
const displayUsername = computed(() => {
  return props.previewData.isAnonymous === 1 ? '匿名用户' : props.previewData.userNickname
})

// 计算显示的头像
const userAvatar = computed(() => {
  return props.previewData.isAnonymous === 1
    ? 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png'
    : props.previewData.userAvatar
})
</script>

<style scoped lang="scss">
.preview-phone {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px 0;
}

.phone-frame {
  width: 300px;
  height: 600px;
  background: #000;
  border-radius: 40px;
  padding: 8px;
  position: relative;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

.phone-notch {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 25px;
  background: #000;
  border-radius: 0 0 20px 20px;
  z-index: 2;
}

.phone-screen {
  width: 100%;
  height: 100%;
  background: #fff;
  border-radius: 32px;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.status-bar {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: #fff;
  font-size: 14px;
  font-weight: 600;

  .time {
    color: #000;
  }

  .indicators {
    display: flex;
    gap: 4px;
    font-size: 12px;
  }
}

.app-header {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: #fff;
  border-bottom: 1px solid #f0f0f0;

  .header-title {
    font-size: 17px;
    font-weight: 600;
    color: #000;
  }

  .header-left,
  .header-right {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #007aff;
    font-size: 16px;
  }
}

.post-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.post-header {
  display: flex;
  align-items: center;
  margin-bottom: 12px;

  .user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 12px;
    object-fit: cover;
  }

  .user-info {
    flex: 1;

    .username {
      font-size: 15px;
      font-weight: 600;
      color: #1d1d1f;
      margin-bottom: 2px;
    }

    .post-meta {
      font-size: 13px;
      color: #86868b;

      .separator {
        margin: 0 4px;
      }
    }
  }
}

.post-content {
  margin-bottom: 16px;

  .post-title {
    font-size: 16px;
    font-weight: 600;
    color: #1d1d1f;
    margin: 0 0 8px 0;
    line-height: 1.4;
  }

  .post-text {
    font-size: 15px;
    color: #1d1d1f;
    line-height: 1.5;
    margin: 0 0 12px 0;
    white-space: pre-wrap;
  }

  .post-tags {
    margin-bottom: 12px;

    .tag {
      display: inline-block;
      font-size: 13px;
      color: #007aff;
      background: rgba(0, 122, 255, 0.1);
      padding: 2px 8px;
      border-radius: 12px;
      margin-right: 6px;
      margin-bottom: 4px;
    }
  }
}

.post-images {
  margin-bottom: 12px;

  .single-image {
    img {
      width: 100%;
      max-height: 200px;
      object-fit: cover;
      border-radius: 8px;
    }
  }

  .grid-images {
    display: grid;
    gap: 4px;
    border-radius: 8px;
    overflow: hidden;

    img {
      width: 100%;
      height: 80px;
      object-fit: cover;
    }

    &:has(.grid-1) {
      grid-template-columns: 1fr;

      img {
        height: 160px;
      }
    }

    &:has(.grid-2) {
      grid-template-columns: 1fr 1fr;
    }

    &:has(.grid-3) {
      grid-template-columns: 1fr 1fr;
      grid-template-rows: 1fr 1fr;

      img:first-child {
        grid-row: 1 / 3;
        height: 164px;
      }
    }

    &:has(.grid-4) {
      grid-template-columns: 1fr 1fr;
      grid-template-rows: 1fr 1fr;
    }
  }

  .carousel-images {
    .carousel-container {
      position: relative;
      border-radius: 8px;
      overflow: hidden;

      img {
        width: 100%;
        height: 160px;
        object-fit: cover;
      }

      .image-count {
        position: absolute;
        top: 8px;
        right: 8px;
        background: rgba(0, 0, 0, 0.6);
        color: #fff;
        padding: 2px 8px;
        border-radius: 12px;
        font-size: 12px;
      }
    }
  }
}

.post-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-top: 1px solid #f2f2f7;

  .action-item {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #86868b;
    font-size: 13px;

    .action-icon {
      font-size: 16px;
    }

    .action-count,
    .action-text {
      font-size: 13px;
    }

    &:hover {
      color: #007aff;
    }
  }
}

/* 滚动条样式 */
.post-container::-webkit-scrollbar {
  width: 2px;
}

.post-container::-webkit-scrollbar-track {
  background: transparent;
}

.post-container::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 1px;
}
</style> 